#include <bits/stdc++.h>

using namespace std;

// 位运算+背包dp

class Solution {
    public:
        int maxTotalReward(vector<int>& rewardValues) {
            sort(rewardValues.begin(), rewardValues.end());
            rewardValues.erase(unique(rewardValues.begin(), rewardValues.end()), rewardValues.end());
            int n = rewardValues.size();
            if (n >= 2 && rewardValues[n - 2] == rewardValues[n - 1] - 1) {
                return 2 * rewardValues[n - 1] - 1;
            }
            bitset<100000> f0, f1;
            f0[0] = 1;
            for (int i = 0, j = 0; i < n; i++) {
                while (j < rewardValues[i]) {
                    f1[j] = f0[j];
                    j++;
                }
                f0 |= f1 << rewardValues[i];
            }
            for (int i = f0.size() - 1; i >= 0 ; --i) {
                if (f0[i]) {
                    return i;
                }
            }
            return 0;
        }
    };

int main() {
    
    //system("pause");
    return 0;
}

